#ifndef PG_SCHOOL_H
#define PG_SCHOOL_H

#include "postgres.h"  // 自身或基础库

#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_class.h"
#include "catalog/pg_namespace.h"
#include "executor/spi.h"
#include "fmgr.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/lwlock.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/elog.h"
#include "utils/fmgroids.h"
#include "utils/geo_decls.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/palloc.h"
#include "utils/rel.h"
#include "utils/typcache.h"

#define SCHEMANAME "changjunhighschool"
#define TABLESCORE "score"
#define TABLESTUDENT "student"
#define SCHEMATABLESCORE "changjunhighschool.score"
#define SCHEMATABLESTUDENT "changjunhighschool.student"
#define TABLESQL "operation_sql_log"
#define TABLEROWS "operation_rows_log"
#define SCHEMATABLESQL "changjunhighschool.operation_sql_log"
#define SCHEMATABLEROWS "changjunhighschool.operation_rows_log"

#define BOOLEAN 1
#define SMALLINT 2
#define BIGINT 3
#define VARCHAR 4
#define TEXT 5
#define INT 6

#define TYPEMAX 6

/* changjunhighschool.student 表的列号定义 */
#define Anum_changjunhighschool_student_is_adult   1
#define Anum_changjunhighschool_student_id         2
#define Anum_changjunhighschool_student_phone      3
#define Anum_changjunhighschool_student_name       4
#define Anum_changjunhighschool_student_address    5


/* changjunhighschool.score 表的列号定义 */
#define Anum_changjunhighschool_score_chinese_score   1
#define Anum_changjunhighschool_score_math_score      2
#define Anum_changjunhighschool_score_evaluate        3
#define Anum_changjunhighschool_score_id              4
#define Anum_changjunhighschool_score_ranking         5

enum op_type
{
    insertType = 1,
    deleteType,
    updateType,
};



// 定义操作标志位的枚举类型
typedef enum {
    OP_INSERT = 1,
    OP_DELETE,
    OP_UPDATE,
    OP_QUERY
} OperationType;

/* 全局标志位，用于标识是否在执行 UDF */
bool is_udf_execution;
/*
 * tools.c
*/

void get_scan_key_params(int16 col_type_oid, char *cmp_operator,
                          StrategyNumber *strategy, RegProcedure *procedure);

AttrNumber get_column_index(char *table_name, char *col_name);

Datum get_datum_by_col_type(AttrNumber col_type, char *new_value);

int get_column_type(char *col_name);

void get_index_type_bycolname(char *tablename, char* colname, int *col_type, AttrNumber* col_index);

bool check_value_exists(Relation rel, 
                        char *update_col1_name, char *new_value1, 
                        char *update_col2_name, char *new_value2, 
                        char *table_name);
                        
Oid get_indexOID(char *col_name);


/*
* pg_stat.c
*/
int log_operateRows(char *tablename, int op, int rows);
void my_exec_spi(OperationType opType, char *sql);

#endif